//
//  LMSlideTabCell.m
//  今日头条
//
//  Created by longmin on 16/6/14.
//  Copyright © 2016年 longmin. All rights reserved.
//

#import "LMSlideTabCell.h"

@interface LMSlideTabCell()

@property(strong, nonatomic) UILabel *titleLabel;

@property(strong, nonatomic) UIColor *selectColor;

@property(nonatomic, strong) UIColor *titleColor;

@end

@implementation LMSlideTabCell

-(UILabel *)titleLabel
{
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
    }
    return _titleLabel;
}

- (void)setLm_select:(BOOL)lm_select {
    _lm_select = lm_select;
    
    if (lm_select) {
        self.titleLabel.textColor = self.selectColor;
    }else {
        self.titleLabel.textColor = self.titleColor;
    }
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleLabel];
    }
    return self;
}
#pragma mark - 设置cell文字/字体/颜色/选中颜色
-(void)setTitle:(NSString *)title titleColor:(UIColor *)color selectColor:(UIColor *)selectColor font:(UIFont *)font
{
    self.titleLabel.text = title;
    self.titleLabel.textColor = color;
    self.titleColor = color;
    self.selectColor = selectColor;
    self.titleLabel.font = font;
    NSDictionary *attributes = @{
                                 NSFontAttributeName : font,
                                 NSForegroundColorAttributeName : color
                                 };
    CGRect titleRect = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
    
    self.titleLabel.frame = CGRectMake(0, 0, titleRect.size.width, titleRect.size.height);
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleLabel.centerX = self.width * 0.5;
    self.titleLabel.centerY = self.height * 0.5;
}

@end
